<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once ("secure_area.php");

class Resellers extends Secure_area {
	public function __construct(){
		parent::__construct();
		$this->load->model('lib_model');
		$this->load->model('admin_resellers_model');
		$this->load->helper('boolean_helper');
	}
	public function index(){
		unset($_SESSION['search_text']);
		$this->page();
	}
	function page(){
		$this->load->library('pagination');
		$start_row = $this->uri->segment(4);
		$limit = 20;
		if(trim($start_row) == ""){
			$start_row = 0;
		}
		$data['title'] = 'Resellers Listing';
		$filter = $this->input->post('search_text');
		if(strlen(trim($filter))){
			unset($_SESSION['search_text']);
			$_SESSION['search_text'] = 	$filter;
		}
		$config['base_url'] = base_url('admin/resellers/page');
		$config['total_rows'] =  $this->admin_resellers_model->listResellers();
		$config['per_page'] = $limit;
		$config['uri_segment'] = 4;
		$config['anchor_class'] = 'class="button pagi" ';
		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();
		$data['main_content'] = 'admin/resellers_listing';
		$data['total_rows'] = $config['total_rows'];
		$data['limit'] = $limit;
		$data['resellers_qry_limited']=$this->admin_resellers_model->listResellers_limited($start_row, $limit);
		$this->load->view('admin/includes/template', $data);
	}
	public function view_account($rid){
		$this->load->helper('boolean_helper');
		$resellerStats = $this->admin_resellers_model->getResellerStats($rid);
		$data['resellerStats'] = $resellerStats;
		$data['accounts'] = $this->admin_resellers_model->getResellerAccounts($rid);
		$data['rid'] = $rid;
		$this->load->view('admin/resellers_account_listing',$data);
	}//end if
	function delete(){
		$id =  isset($_POST['checkid']) ? $_POST['checkid'] : null;
		if( !empty( $id )){
			if( $this->admin_resellers_model->deleteUser( $id ) ){
				$this->message->set('success','Successfully deleted resellers!');
			} else {
				$this->message->set('error','Failed to delete resellers!');
			}
		} else {
			$this->message->set('error','Please select from the list to delete record');
		}
		redirect('admin/resellers');
	}
	function change_status(){
		$status = $this->input->post('status');
		$userid = $this->input->post('userid');
		echo ($this->admin_resellers_model->update_user_status($userid,$status))? boolean_helper::status($status, true,$userid):'';
	}//end fct

	/*function ffdelete(){
		$this->load->model('admin_resellers_model');
		$task = isset($_POST['task']) ? strtolower($_POST['task']) : '' ;
		switch($task){
			case 'delete':
				$id =  isset($_POST['checkid']) ? $_POST['checkid'] : null;
				if( !empty( $id )){
					//$this->delete($id);
					if( $this->admin_resellers_model->deleteUser( $id ) ){
						$this->message->set('success','Successfully deleted user!');
					} else {
						$this->message->set('error','Failed to delete user!');
					}
				} else {
					$this->message->set('error','Please select from the list to delete record');
				}
				break;

			default:

				break;
		}
		redirect('admin/resellers');
	}*/
}
